home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / earcd / dev / mui / mui37_de.lha / Amiga-E / Examples / Appwindow.e next >
Text File  |  1996-08-25  |  4KB  |  136 lines

  1. /*
  2. **  Original C Code written by Stefan Stuntz
  3. **
  4. **  Translation into E by Klaus Becker
  5. **
  6. **  All comments are from the C-Source
  7. */
  8.  
  9. OPT PREPROCESS
  10.  
  11. MODULE 'muimaster','libraries/mui','libraries/muip',
  12.        'mui/muicustomclass','amigalib/boopsi',
  13.        'intuition/classes','intuition/classusr',
  14.        'intuition/screens','intuition/intuition',
  15.        'utility/tagitem','utility/hooks','tools/installhook',
  16.        'wb','workbench/startup','workbench/workbench'
  17.  
  18. /*
  19. ** App message callback hook. Note that the object given here
  20. ** is the object that called the hook, i.e. the one that got
  21. ** the icon(s) dropped on it.
  22. */
  23.  
  24. PROC appMsgFunc(obj,x:PTR TO LONG)
  25.   DEF ap:PTR TO wbarg,
  26.       amsg:PTR TO appmessage,
  27.       i,
  28.       buf[256]:STRING,b
  29.   amsg:=x[]
  30.   b:=buf;i:=0
  31.   ap:=amsg.arglist
  32.   WHILE (i<amsg.numargs)
  33.     NameFromLock(ap.lock,buf,StrMax(buf))
  34.     AddPart(buf,ap.name,StrMax(buf))
  35.     doMethodA(obj,[MUIM_List_Insert,{b},1,MUIV_List_Insert_Bottom])
  36.     ap++
  37.     i++
  38.   ENDWHILE
  39. ENDPROC 0
  40.   
  41. /*
  42. ** Having a function instead of a macro saves some code.
  43. */
  44.  
  45. PROC makeLV() IS
  46.   ListviewObject,
  47.     MUIA_Listview_Input, FALSE,
  48.     MUIA_Listview_List , ListObject,
  49.       ReadListFrame,
  50.       MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
  51.       MUIA_List_DestructHook , MUIV_List_DestructHook_String ,
  52.     End,
  53.   End
  54.  
  55. PROC main() HANDLE
  56.   DEF app,window,sigs=0,
  57.       lv1,lv2,lv3,
  58.       appMsgHook:hook
  59.  
  60.   IF (muimasterbase:=OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN))=NIL THEN
  61.     Raise('Failed to open muimaster.library')
  62.  
  63.   installhook(appMsgHook,{appMsgFunc})
  64.  
  65.   app:=ApplicationObject,
  66.     MUIA_Application_Title      , 'AppWindowDemo',
  67.     MUIA_Application_Version    , '$VER: AppWindowDemo 12.9 (21.11.95)',
  68.     MUIA_Application_Copyright  , 'c1992/93, Stefan Stuntz',
  69.     MUIA_Application_Author     , 'Stefan Stuntz & Klaus Becker',
  70.     MUIA_Application_Description, 'Show AppWindow Handling',
  71.     MUIA_Application_Base       , 'APPWINDOWDEMO',
  72.     SubWindow, window:= WindowObject,
  73.       MUIA_Window_Title    , 'Drop icons on me!',
  74.       MUIA_Window_ID       , "APPW",
  75.       MUIA_Window_AppWindow, MUI_TRUE,
  76.       WindowContents, VGroup,
  77.         Child, HGroup,
  78.           Child, lv1:= makeLV(),
  79.           Child, lv2:= makeLV(),
  80.         End,
  81.         Child, lv3:= makeLV(),
  82.       End,
  83.     End,
  84.   End
  85.  
  86.   IF (app=NIL) THEN Raise('Failed to create Application.')
  87.  
  88.   doMethodA(window,[MUIM_Notify,MUIA_Window_CloseRequest,MUI_TRUE,
  89.     app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit])
  90.  
  91. /*
  92. ** Call the AppMsgHook when an icon is dropped on a listview.
  93. */
  94.  
  95.   doMethodA(lv1,[MUIM_Notify,MUIA_AppMessage,MUIV_EveryTime,
  96.     lv1,3,MUIM_CallHook,appMsgHook,MUIV_TriggerValue])
  97.  
  98.   doMethodA(lv2,[MUIM_Notify,MUIA_AppMessage,MUIV_EveryTime,
  99.     lv2,3,MUIM_CallHook,appMsgHook,MUIV_TriggerValue])
  100.  
  101.   doMethodA(lv3,[MUIM_Notify,MUIA_AppMessage,MUIV_EveryTime,
  102.     lv3,3,MUIM_CallHook,appMsgHook,MUIV_TriggerValue])
  103.  
  104. /*
  105. ** When we're iconified, the object lv3 shall receive the
  106. ** messages from icons dropped on our app icon.
  107. */
  108.  
  109.   set(app,MUIA_Application_DropObject,lv3)
  110.  
  111. /*
  112. ** This is the ideal input loop for an object oriented MUI application.
  113. ** Everything is encapsulated in classes, no return ids need to be used,
  114. ** we just check if the program shall terminate.
  115. ** Note that MUIM_Application_NewInput expects sigs to contain the result
  116. ** from Wait() (or 0). This makes the input loop significantly faster.
  117. */
  118.  
  119.   set(window,MUIA_Window_Open,MUI_TRUE)
  120.  
  121.   WHILE doMethodA(app,[MUIM_Application_NewInput,{sigs}]) <> MUIV_Application_ReturnID_Quit
  122.     IF sigs THEN sigs:=Wait(sigs)
  123.   ENDWHILE
  124.  
  125.   set(window,MUIA_Window_Open,FALSE)
  126.  
  127. /*
  128. ** Shut down...
  129. */
  130.  
  131. EXCEPT DO
  132.   IF app THEN Mui_DisposeObject(app)
  133.   IF muimasterbase THEN CloseLibrary(muimasterbase)
  134.   IF exception THEN WriteF('\s\n',exception)
  135. ENDPROC
  136.